package mr.ali.webvideo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import mr.ali.webvideo.model.CollectionPlayComment;
import mr.ali.webvideo.mapper.CollectionPlayCommentMapper;
import mr.ali.webvideo.service.ICollectionPlayCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr-ali
 * @since 2025-08-16
 */
@Service
public class CollectionPlayCommentServiceImpl extends ServiceImpl<CollectionPlayCommentMapper, CollectionPlayComment> implements ICollectionPlayCommentService {

    @Resource
    private CollectionPlayCommentMapper collectionPlayCommentMapper;

    @Override
    public PageInfo<CollectionPlayComment> getCollectionCommentList(Integer pageNum, Integer pageSize, Integer videoId) {
        QueryWrapper<CollectionPlayComment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("video_id", videoId);
        queryWrapper.orderByDesc("time");
        PageHelper.startPage(pageNum, pageSize);
        List<CollectionPlayComment> pageInfo = collectionPlayCommentMapper.selectList(queryWrapper);
        return new PageInfo<>(pageInfo);
    }

    /**
     * 插入新评论
     */
    @Override
    public CollectionPlayComment insertComment(CollectionPlayComment collectionPlayComment) {
        Integer row = collectionPlayCommentMapper.insert(collectionPlayComment);
        if (row == 1) {
            return collectionPlayComment;
        }
        return null;
    }
}
